{extend name="common/base_page" /}

{block name="title"}出库管理{/block}

{block name="jscssfile"}
<link href="__STATIC__/easy_search/searchPlug.css?v={$site.version}" type='text/css'/>
{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.layui-fluid {
    padding-top: 5px;
}
.layui-table td{
  padding: 9px 5px;
  font-size: 13px;
}
input:disabled { background:#dddddd; }
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card-body public-tpl-row1" style="padding: 0px;">
        <form class="layui-form" action="" id="info-form" lay-filter="info-form" onsubmit="return false;">
        <fieldset class="layui-elem-field layui-field-title"><legend>出库信息</legend></fieldset>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label"><i class="c-red">*</i>出库日期</label>
                <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="create_time" id="create_time" autocomplete="off" class="layui-input" value="{if $info.create_time gt 0}{$info.create_time|date='Y-m-d'}{else}{:date('Y-m-d')}{/if}" readonly="true">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">出库方式</label>
                <div class="layui-input-inline" style="width:300px;">
                    <select name="entry_sub_type" lay-filter="entry_sub_type">
                        {volist name="rk_type_list" id="zhtype"}
                        <option value="{$zhtype.id}" {if $info.entry_sub_type eq $zhtype.id}selected="true"{/if}>{$zhtype.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">领用科室</label>
                <div class="layui-input-inline" style="width:300px;">
                    <select name="out_keshi" lay-filter="out_keshi" lay-search>
                        <option value="" {if $info.out_keshi eq ''}selected="true"{/if}>请选择</option>
                        {volist name="keshi_list" id="zhtype"}
                        <option value="{$zhtype.name}" {if $info.out_keshi eq $zhtype.name}selected="true"{/if}>{$zhtype.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label">领用人员</label>
                <div class="layui-input-inline" style="width:300px;">
                    <select name="out_renyuan" lay-filter="out_renyuan" lay-search>
                        <option value="" {if $info.out_renyuan eq ''}selected="true"{/if}>请选择</option>
                        {volist name="admin_list" id="vo"}
                        <option value="{$vo.nickname}" {if $info.out_renyuan eq $vo.nickname}selected="true"{/if}>{$vo.nickname}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">出库备注</label>
                <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="remarks" autocomplete="off" class="layui-input" value="{$info.remarks}">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">出库总金额</label>
                <div class="layui-input-inline" style="width:300px;">
                <input type="text" name="total_price" autocomplete="off" class="layui-input" value="{$info.total_price}" disabled="true">
                </div>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title"><legend>出库项目明细</legend></fieldset>
        <div class="layui-form-item" style="margin-bottom:0px;">
            <div class="layui-input-block" style="margin-left:0px;">
                  <div class="layui-inline"><label class="layui-form-label">搜索查询</label>
                    <div class="layui-input-inline" style="width:500px;">
                      <input type="text" name="keyword" id="keyword" maxlength="10" placeholder="名称/编码/拼音码/五笔码" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-inline">
                        <a class="layui-btn layui-btn-normal layui-btn-warm" onclick="$('#subListBox').empty();reloadListPrice();">全部清空</a>
                  </div>
            </div>
        </div>
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" style="margin-top:5px;padding:0px 0px;height: 500px;overflow-y: scroll;">
                        <table class="layui-table">
                          <colgroup>
                            <col width="200">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col width="60">
                            <col width="115">
                            <col width="115">
                            <col width="110">
                            <col width="120">
                            <col width="60">
                            <col>
                          </colgroup>
                          <thead>
                            <tr>
                              <th>名称</th>
                              <th>规格</th>
                              <th><i class="c-red">*</i>出库数量</th>
                              <th>库存数量</th>
                              <th>单位</th>
                              <th>零售单价（元）</th>
                              <th>进货单价(元)</th>
                              <th>批号</th>
                              <th>有效期</th>
                              <th>操作</th>
                            </tr>
                          </thead>
                          <tbody id="subListBox">
                          {volist name="table_list" id="vo"}
                            <tr data-id="{$vo.id}" data-num="{$vo.ext_json.num}" data-price="{$vo.price}" data-json='{:json_encode($vo['ext_json'],JSON_UNESCAPED_UNICODE)}' id="tr_{$vo.id}">
                                <td>{$vo.name}</td>
                                <td>{$vo.spec}</td>
                                <td><input type="text" id="tr_iptnum_{$vo.id}" autocomplete="off" class="layui-input" value="{$vo.num}" style="height: 28px;"></td>
                                <td>{$vo.ext_json.num}</td>
                                <td>{$vo.unit}</td>
                                <td>{$vo.ls_price}/{$vo.unit}</td>
                                <td>{$vo.price}/{$vo.unit}</td>
                                <td>{$vo.batch_sn}</td>
                                <td>{$vo.except_time}</td>
                                <td><a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delTr('#tr_{$vo.id}');">删除</a></td>
                            </tr>
                          {/volist}
                          </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-layout-admin">
              <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                  <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="info-form-savebtn1">保存</button>
                  <button type="reset" class="layui-btn layui-btn-danger" id="resetBtn">重置</button>
                  <a class="layui-btn layui-btn-primary" href="{:url('index/store.outstore/index')}">返回</a>
                </div>
              </div>
            </div>
            <input type="hidden" name="id" value="{$info.id}"/>
        </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="__STATIC__/easy_search/searchPlug.js?v={$site.version}"></script>
<script src="__INDEX__/js/store/chuku.js?v={$site.version}"></script>
<script type="text/javascript">
$(function(){
  setTimeout(function(){
    //日期范围
    laydate.render({ elem: '#create_time' });
    //保存数据
    layform.on('submit(info-form-savebtn1)', function(data){
      data.field.table_list = getListData(); //列表信息
      if(Object.keys(data.field.table_list).length <= 0)
      {
          layer.msg('请先添加出库项目明细后再保存', {time: 2000,anim: 4});
          return false;
      }
      layer.confirm('确定要保存出库项目信息吗？', {
          title:'保存',shade:[0.4,'#000000'],btn: ['确定','取消'],
          btn1:function(){
              layer.closeAll();
              _Index.ajax("{:url('index/store.outstore/info')}",data.field,function(d){
                if(d.err == 0)
                {
                  $('#subListBox').empty();
                  reloadListPrice();
                  $('#resetBtn').trigger('click');
                  layer.msg(d.msg, {time: 1000},function(){ 
                    window.location.href = "{:url('index/store.outstore/index')}";
                  });
                }else{
                  layer.msg(d.msg, {time: 2000,anim: 4});
                }
              },'请稍候...');
          }
      });
      return false;
    });
    {if $info}
    $('#subListBox tr').each(function(i,v){
        var _id = parseInt($(this).data('id'));
        var _idKeyName = _id;
        //初始化列表
        _initTableList(_idKeyName,false);
    });
    {/if}
    layform.render();
  },50);
  //搜索明细项目
  $.myEasySearch({
      selector:"#keyword",
      url:"{:url('index/store.instore/find_instore_list')}",
      height:200,
      header:[
          {title:"名称",field:"name",width:180},
          {title:"规格",field:"spec",width:80},
          {title:"库存",field:"num",width:50},
          {title:"进货单价",field:"price",width:80},
          {title:"单位",field:"unit",width:70},
          {title:"批号",field:"batch_sn",width:100},
          {title:"有效期",field:"except_time",width:90},
          {title:"生产商",field:"changjia",width:120},
          {title:"供应商",field:"gys_name",width:120},
      ],
      click:function(d,o){
          //设置-列表
          setTableTbodyHtml(d);
      }
  });
});
</script>
{/block}